package map.abstractor.xaml2uimodel.base;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
 * Class XMLErrorHandler
 * 		 implements ErrorHandler
 *	
 */
public class XMLErrorHandler implements ErrorHandler{
	
	protected String message(SAXParseException e) {
		String message = "Message : " + e.getMessage() + "\n";
		message += "Ligne " + e.getLineNumber() + ", colonne "
				+ e.getColumnNumber() + "\n";
		message += "Public id : " + e.getPublicId() + "\n";
		message += "System id : " + e.getSystemId();
		return message;
	}

	protected void printSAXException(SAXParseException e) {
		System.out.println(message(e));
		if (e.getException() != null) {
			e.getException().printStackTrace();
		}
	}

	public void warning(SAXParseException exception) throws SAXException {
		System.out.println("*** Warning ***");
		printSAXException(exception);
	}

	public void error(SAXParseException exception) throws SAXException {
		System.out.println("*** Erreur ***");
		printSAXException(exception);
	}

	public void fatalError(SAXParseException exception) throws SAXException {
		String message = "*** Erreur fatale ***\n";
		message += message(exception);
		SAXException se = new SAXException(message, exception);
		throw se;
	}
	
}
